package com.netty.rpc.protocol.server;

import com.netty.rpc.protocol.client.MessageHandler;
import com.netty.rpc.common.entity.NettyRpcMessage;
import com.netty.rpc.common.entity.NettyRpcRequest;
import com.netty.rpc.common.entity.NettyRpcResponse;
import com.netty.rpc.common.delegate.NettyRpcDelegateImpl;


public abstract class AbstractRequestHandler extends NettyRpcDelegateImpl implements MessageHandler {


    public abstract void handle(NettyRpcRequest request, NettyRpcResponse response);

    @Override
    public void beforeHandle(NettyRpcMessage nettyRpcMessage) {

        if (nettyRpcMessage instanceof NettyRpcResponse) {
            NettyRpcResponse response = (NettyRpcResponse) nettyRpcMessage;
            response.setStartHandleTime(System.currentTimeMillis());
        }
    }

    @Override
    public void afterHandle(NettyRpcMessage nettyRpcMessage) {

        if (nettyRpcMessage instanceof NettyRpcResponse) {
            NettyRpcResponse response = (NettyRpcResponse) nettyRpcMessage;
            response.setEndHandleTime(System.currentTimeMillis());
        }

    }
}
